/* reworp05.p - REPETITIVE WIP STATUS REPORT                                  */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Id:: reworp05.p 2366 2010-11-10 01:47:19Z zzh                          $: */
/*                                                                            */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 03/29/95   BY: WUG *F0PN*                */
/* REVISION: 8.6      LAST MODIFIED: 10/14/97   BY: GYK *K0YN*                */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* Annasaheb Rahane   */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 07/25/00   BY: *N0GQ* Mudit Mehta        */
/* REVISION: 9.1      LAST MODIFIED: 10/05/00   BY: *N0RQ* Jean Miller        */
/* Revision: 1.5.3.9     BY: Paul Donnelly (SB)   DATE: 06/28/03  ECO: *Q00K* */
/* Revision: 1.5.3.10  BY: Robin McCarthy       DATE: 06/07/06  ECO: *R04J* */
/*-Revision end---------------------------------------------------------------*/

{us/mf/mfdtitle.i "1+ "}
{us/wo/woconsdf.i}

define variable line     like wo_line no-undo.
define variable line1    like wo_line label "To" no-undo.
define variable lot      like wo_lot no-undo.
define variable lot1     like wo_lot label "To" no-undo.
define variable part     like wo_part no-undo.
define variable part1    like wo_part label "To" no-undo.
define variable site     like wo_site no-undo.
define variable site1    like wo_site label "To" no-undo.
define variable endeff   as date label "End Effective" no-undo.
define variable endeff1  as date label "To" no-undo.
define variable first_op like mfc_logical no-undo.
define variable moved_in like wr_qty_cummove label "Cum Moved In" no-undo.
define  variable altpart          like ptal_alt_part no-undo.
define  variable altpart1         like ptal_alt_part no-undo.
define  variable order_type_key  like lngd_key1 initial "0".
define  variable c-lngd-dataset like lngd_det.lngd_dataset
   initial "wo_mstr" no-undo.
define variable orderType as character format "x(9)"
   label "Include Repetitive/Discrete/Both" no-undo.
define variable inque_label  as character format "x(13)"
   label "Input Queue" no-undo.
define variable outque_label as character format "x(13)"
   label "Output Queue" no-undo.
define variable rejque_label as character format "x(13)"
   label "Reject Queue" no-undo.
define variable inque_value  as decimal format "->>,>>>,>>9.9<<<<<<<<"
   label "Quantity" no-undo.
define variable outque_value as decimal format "->>,>>>,>>9.9<<<<<<<<"
   label "Quantity" no-undo.
define variable rejque_value as decimal format "->>,>>>,>>9.9<<<<<<<<"
   label "Quantity" no-undo.
define variable h_wiplottrace_funcs as handle no-undo.
define variable beginquelabel  as character no-undo.
define variable procinlabel    as character no-undo.
define variable procoutlabel   as character no-undo.
define variable curquelabel    as character no-undo.
define variable movedinlabel   as character no-undo.
define variable movedoutlabel  as character no-undo.
define variable rejectinlabel  as character no-undo.
define variable rejectoutlabel as character no-undo.
define variable reworkinlabel  as character no-undo.
define variable reworkoutlabel as character no-undo.
define variable scraplabel     as character no-undo.
define variable adjustlabel    as character no-undo.

assign
   beginquelabel    = getTermLabel("BEGIN_QTY",13)
   procinlabel      = "+" + getTermLabel("PROCESSED",12)
   procoutlabel     = "-" + getTermLabel("PROCESSED",12)
   curquelabel      = getTermLabel("CURRENT_QTY",13)
   movedinlabel     = "+" + getTermLabel("MOVED_IN",12)
   movedoutlabel    = "-" + getTermLabel("MOVED_OUT",12)
   rejectinlabel    = "+" + getTermLabel("REJECTED",12)
   rejectoutlabel   = "-" + getTermLabel("REJECTED",12)
   reworkinlabel    = "+" + getTermLabel("REWORKED",12)
   reworkoutlabel   = "-" + getTermLabel("REWORKED",12)
   scraplabel       = "-" + getTermLabel("SCRAPPED",12)
   adjustlabel      = "-" + getTermLabel("ADJUSTED",12).

{us/wl/wlfnc.i} /* FUNCTION FORWARD DECLARATIONS */

form
   lot          colon 20
   lot1         colon 45    
   part         colon 20    
   part1        colon 45    
   site         colon 20    
   site1        colon 45    
   line         colon 20
   line1        colon 45
   endeff       colon 20
   endeff1      colon 45
   altpart      colon 20
   altpart1     colon 45 label "To" skip(1)
   orderType    colon 45 skip
with frame a side-labels width 80.
/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

find first gl_ctrl
   where gl_ctrl.gl_domain = global_domain
no-lock.

for first lngd_det
   where lngd_dataset = c-lngd-dataset
   and lngd_field   = "orderType"
   and lngd_lang    = global_user_lang
   and lngd_key1    = order_type_key
no-lock:
end.

if available lngd_det then
   orderType = lngd_key2.
else
   orderType = "".

{us/gp/gpbrparm.i &browse=wolu200.p &parm=c-brparm1 &val=""""}
{us/gp/gpbrparm.i &browse=wolu200.p &parm=c-brparm2 &val=""""}
{us/gp/gpbrparm.i &browse=wolu200.p &parm=c-brparm3 &val=""""}
{us/gp/gpbrparm.i &browse=wolu200.p &parm=c-brparm4 &val=""""}
{us/gp/gpbrparm.i &browse=wolu200.p &parm=c-brparm5 &val=""""}

{us/wb/wbrp01.i}

repeat:

   if lot1 = hi_char then lot1 = "".
   if part1 = hi_char then part1 = "".
   if site1 = hi_char then site1 = "".
   if line1 = hi_char then line1 = "".
   if altpart1   = hi_char  then altpart1  = "".

   if c-application-mode <> 'web' then
   update
      lot lot1
      part part1
      site site1
      line line1
      endeff endeff1
      altpart
      altpart1
      orderType
   with frame a
      editing:
      if frame-field = "orderType"
      then do:
         {us/mf/mfnp05.i lngd_det lngd_det
            "lngd_dataset   = c-lngd-dataset
              and lngd_field  = 'orderType'
              and lngd_lang   = global_user_lang"
            lngd_key2 "input orderType" }
         if recno <> ? then
         display lngd_key2 @ orderType
         with frame a.
      end.
      else do:
         status input.
         readkey.
         apply lastkey.
      end.
   end.

   {us/wb/wbrp06.i &command = update
      &fields = "  lot lot1 part part1 site site1
        line line1 endeff endeff1 altpart altpart1 orderType"
      &frm = "a"}

   if (c-application-mode <> 'web') or
      (c-application-mode = 'web' and
      (c-web-request begins 'data'))
   then do:

      bcdparm = "".
      {us/mf/mfquoter.i lot          }
      {us/mf/mfquoter.i lot1         }
      {us/mf/mfquoter.i part         }
      {us/mf/mfquoter.i part1        }
      {us/mf/mfquoter.i site         }
      {us/mf/mfquoter.i site1        }
      {us/mf/mfquoter.i line         }
      {us/mf/mfquoter.i line1        }
      {us/mf/mfquoter.i endeff           }
      {us/mf/mfquoter.i endeff1          }
      {us/mf/mfquoter.i altpart}
      {us/mf/mfquoter.i altpart1}
      {us/mf/mfquoter.i orderType}

      if lot1 = "" then lot1 = hi_char.
      if part1 = "" then part1 = hi_char.
      if site1 = "" then site1 = hi_char.
      if line1 = "" then line1 = hi_char.
      if altpart1 = "" then altpart1  = hi_char.

   end.

   for first lngd_det
      where lngd_dataset = c-lngd-dataset
      and   lngd_field   = "orderType"
      and   lngd_lang    = global_user_lang
      and   lngd_key2    = orderType
   no-lock:
   end.

   if not available lngd_det
   then do:

      /* MUST BE (S)cheduled or (D)iscrete or (B)oth */
      {us/bbi/pxmsg.i &MSGNUM=10346 &ERRORLEVEL=4}

      if c-application-mode = "WEB"
         then
         return.
      else
      next-prompt
         orderType with frame a.
      undo,retry.
   end.

   order_type_key=lngd_key1.

   /* OUTPUT DESTINATION SELECTION */
   {us/gp/gpselout.i &printType = "printer"
               &printWidth = 132
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "yes"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
   {us/bbi/mfphead.i}

   /*NOTE: LOOK AT ALL ORDERS CLOSED OR NOT*/
   moved_in = 0.

   mainloop:
   for each wo_mstr no-lock
      where wo_mstr.wo_domain = global_domain
      and (wo_lot >= lot and wo_lot <= lot1
           and wo_part >= part and wo_part <= part1
           and wo_site >= site and wo_site <= site1
           and wo_line >= line and wo_line <= line1
           and (wo_due_date >= endeff or endeff = ?)
           and (wo_due_date <= endeff1 or endeff1 = ?))
      and ((altpart = "" and altpart1 = hi_char)
            or can-find(first ptal_mstr
                        where ptal_mstr.ptal_domain = global_domain
            and ptal_part             = wo_part
            and ptal_alt_part         >= altpart
            and ptal_alt_part         <= altpart1
            and ptal_active))
      and ((wo_mfg_type = {&MFG_TYPE_DISCRETE}
      and wo_type <> "S"
      and (order_type_key = {&MFG_TYPE_DISCRETE}
           or order_type_key = {&MFG_TYPE_DISCRETE_AND_REPETITIVE}))
      or (wo_mfg_type = {&MFG_TYPE_REPETITIVE}
          and wo_type <> "S"
          and (order_type_key = {&MFG_TYPE_REPETITIVE}
               or order_type_key = {&MFG_TYPE_DISCRETE_AND_REPETITIVE})))

   use-index wo_type_part,
   each pt_mstr no-lock
      where pt_mstr.pt_domain = global_domain
      and   pt_part = wo_part,
   each pl_mstr no-lock
      where pl_mstr.pl_domain = global_domain
      and   pl_prod_line = pt_prod_line
   by substring(wo_type,1,1)
   by wo_site
   by wo_part
   by wo_line
   by wo_due_date
   by wo_lot:

      {us/bbi/gprun.i ""rewodisp.p"" "(input wo_lot)"}

      display skip with frame dummy1.

      for each wr_route no-lock
         where wr_route.wr_domain = global_domain
         and   wr_lot = wo_lot
      break by wr_op with frame f-a:

         if page-size - line-counter < 9 then page.

         form
            wr_op                  column-label "Op"
            wr_desc
            wr_milestone       column-label "Mile-!stone"
            space(3)
            inque_label
            inque_value
            space(3)
            outque_label
            outque_value
            space(3)
            rejque_label
            rejque_value
         with frame f-a width 132 no-box.
         /* SET EXTERNAL LABELS */
         setFrameLabels(frame f-a:handle).

         first_op = first(wr_op).

         display
            wr_op
            wr_desc
            wr_milestone.
         /*display the right part*/
         {us/re/rewoiq05.i}


         /* WIP STATUS INQUIRY/REPORT INCLUDE                                          */

         assign
            inque_label  = beginquelabel
            inque_value  = wr_qty_inqueb
            outque_label = beginquelabel
            outque_value = wr_qty_outqueb
            rejque_label = beginquelabel
            rejque_value = wr_qty_rejqueb.

         display

            inque_label
            inque_value
            outque_label
            outque_value
            rejque_label
            rejque_value.

         down 1.

         assign
            inque_label = movedinlabel
            inque_value = moved_in
            outque_label = procinlabel
            outque_value = wr_qty_cumproc
            rejque_label = rejectinlabel
            rejque_value = wr_qty_cumrjct.

         display
            inque_label
            inque_value
            outque_label
            outque_value
            rejque_label
            rejque_value.

         down 1.

         assign
            inque_label  = procoutlabel
            inque_value  = wr_qty_cumproc
            outque_label = reworkinlabel
            outque_value = wr_qty_cumrwrk
            rejque_label = reworkoutlabel
            rejque_value = wr_qty_cumrwrk.

         display
            inque_label
            inque_value
            outque_label
            outque_value
            rejque_label
            rejque_value.

         down 1.

         assign
            inque_label  = curquelabel
            inque_value  = wr_qty_inque
            outque_label = rejectoutlabel
            outque_value = wr_qty_cumrjct
            rejque_label = scraplabel
            rejque_value = wr_qty_cumrscrap.

         display
            inque_label
            inque_value
            outque_label
            outque_value
            rejque_label
            rejque_value.

         down 1.

         assign
            outque_label = movedoutlabel
            outque_value = wr_qty_cummove
            rejque_label = adjustlabel
            rejque_value = wr_qty_cumradj.

         display
            outque_label
            outque_value
            rejque_label
            rejque_value.

         down 1.

         assign
            outque_label = scraplabel
            outque_value = wr_qty_cumoscrap
            rejque_label = curquelabel
            rejque_value = wr_qty_rejque.

         display
            outque_label
            outque_value
            rejque_label
            rejque_value.

         down 1.

         assign
            outque_label = adjustlabel
            outque_value = wr_qty_cumoadj.

         display
            outque_label
            outque_value.

         down 1.

         assign
            outque_label = curquelabel
            outque_value = wr_qty_outque.

         display
            outque_label
            outque_value.

         down 1



         down 1.

         {us/mf/mfrpchk.i &label=mainloop}
         /*display wip lot inventory */
         if is_wiplottrace_enabled()
         then do:
            {us/bbi/gprun.i ""rewoiqa.p""
                     "(input wr_lot,
                       input wr_op,
                       input pt_um)"}
         end.

         pause 0.

         display
            skip(1)
         with frame dummy3.

         moved_in = wr_qty_cummove.

      end.

      display
         skip(1)
      with frame dummy2.

      {us/mf/mfrpchk.i}

   end.

   {us/mf/mfrtrail.i}

end.

{us/wb/wbrp04.i &frame-spec = a}
